<template>
    <div class="app-container calendar-list-container">
    <!-- filter 条件查询 -->
    <div class="filter-container">
      <el-input
            @keyup.enter.native="getData"
            clearable
            v-model="listQuery.jobNumber"
            style="width: 150px;margin-right:15px;margin-top:7px"
            class="filter-item"
            placeholder="请输入员工工号"
      ></el-input>

      <el-date-picker
        v-model="listQuery.startTime"
        value-format="timestamp"
        format="yyyy-MM-dd"
        placeholder="选择开始日期"
        style="width: 150px;margin-right:15px;" class="filter-item"
      >
      </el-date-picker>
      <el-date-picker
        v-model="listQuery.endTime"
        format="yyyy-MM-dd"
        value-format="timestamp"
        placeholder="选择结束日期"
          style="width: 150px;margin-right:15px;" class="filter-item"
      ></el-date-picker>
      <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="getData">搜索</el-button>
    </div>

    <!-- table 表格 -->
    <el-table  :data="tableInfo" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%">
      <el-table-column  label="序号" type="index" align="center" width="80px"/>
      <el-table-column label="员工姓名"  prop="userName" align="center" width="100px"/>
      <el-table-column  label="员工工号" prop='jobNumber' align="center" width="100px"/>
      <el-table-column  label="首次绑定时间" prop='firstTime' align="center" width="200px"/>
      <el-table-column  label="最后解绑时间" prop='lastTime' align="center" width="200px"/>
      <el-table-column  label="考勤日期" prop='attendanceDay' align="center" width="200px"/>
      <el-table-column  label="工作时间(min)"  prop="countTime" align="center"/>
    </el-table>
   
   <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[5,10, 20, 30, 40, 100, 300, 500]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
 
  </div>
</template>

<script>
import { attendancePage } from '@/api/performance.js'
export default {
    data() {
        return {
            total: 0,                           //数据的总数
            listQuery: {
                endTime: '',                     //结束时间
                startTime: '',                   //开始时间
                jobNumber: '',                    //员工工号
                page: 1,
                limit: 10
            },
            tableInfo: [],
            loadingList: false
        }
    },
    methods: {
    // 搜索按钮绑定的函数，向服务器发送表单数据
    // 所有传输的表单字段都不是必须的，按需查询
    async handleFilter() {
      this.loadingList = true
      let query = Object.assign({},this.listQuery)
      query.startTime = query.startTime == null ? '' : query.startTime
      query.endTime = query.endTime == null ? '' : query.endTime
      let {data} = await attendancePage(query)
      this.tableInfo = data.records
      this.total = data.total
      this.loadingList = false
    },
    // 修改按钮绑定的函数，将整行的内容取好跳转到修改页面
    handleEdit(item) {
      this.$router.push({
        path: 'updateData_List',
        name: 'updateData_List',
        params: item
      })
    },
    // 删除用户按钮,使用elementui的messageBox弹框组件
    // 传入的数据是数据所在的行数以及该条目所有的信息
    handleDelete(index,row) {
      this.$confirm('这将会永久删除该行数据，是否继续?', '警告', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(async () => {
          let res = await delPerformance({performanceId: row.performanceId})
          this.tableInfo.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功'
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
     // 获取角色列表下拉框数据
    async getRoleInfo() {
      let {data} = await getRoleList()
      this.roleList = data
    },
    // 获取部门下拉框数据
    async getDepartInfo() {
      let {data} = await getDepartList()
      this.departList = data
    }, 
    // table表单下方的页码组件改变每页显示的数据条数
     handleSizeChange(val) {
      this.listQuery.limit = val
      this.handleFilter()
    },
    // table表单下方的页码组件改变页面
     handleCurrentChange(val) {
      this.listQuery.page = val
      this.handleFilter()
    },
    getData() {
      this.listQuery.page = 1
      this.listQuery.limit = 10
      this.handleFilter()
    },
  },
  // 进入页面获取table信息
  mounted() {
    this.handleFilter()
  }
}
</script>

<style>

</style>